package com.stream.controller;

import com.stream.model.entity.ScheduleJobLogEntity;
import com.stream.service.ScheduleJobLogService;
import com.stream.utils.PageUtils;
import com.stream.utils.Query;
import com.stream.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 定时任务日志
 * Created by Stream on 2017/7/2.
 */

@RestController
@RequestMapping("/sys/scheduleLog")
public class ScheduleJobLogController {

    @Autowired
    private ScheduleJobLogService scheduleJobLogService;

    /**
     * 定时任务日志列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ScheduleJobLogEntity> list = scheduleJobLogService.queryList(query);
        int total = scheduleJobLogService.queryTotal(query);
        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());

        return R.ok().put("page", page);
    }

    /**
     * 定时任务日志信息
     */
    @RequestMapping("/info/{logId}")
    public R info(@PathVariable("logId") Long logId) {
        ScheduleJobLogEntity jobLog = scheduleJobLogService.queryObject(logId);

        return R.ok().put("log", jobLog);
    }
}
